package com.acme.bankapp.dal;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;

import com.acme.bankapp.domain.bank.Bank;


public class BankSerializationDAO {
	public static void saveBank(Bank bank, OutputStream sink) throws IOException {
		ObjectOutputStream oos = new ObjectOutputStream(sink);
		
		try {
			oos.writeObject(bank);
		} finally {
			oos.close();
		}
	}
	
	public static Bank readBank(InputStream source) throws IOException, ClassNotFoundException {
		ObjectInputStream ois = new ObjectInputStream(source);
		
		Bank bank;
		try {
			bank = (Bank)ois.readObject();
		} finally {
			ois.close();
		}
		
		return bank;
	}
}
